#include<iostream>
using namespace std;
const int N=100001;
int stk[N],tt=0;
int main()
{
    int x;
    cin>>x;
    for(int i=0;i<x;i++)
    {
        int n;
        cin>>n;
        while(tt&&stk[tt]>=n)tt--;
        if(tt)
        {
            cout<<stk[tt]<<" ";
            
        }
        else cout<<"-1"<<" ";
        stk[++tt]=n;
    }
    
    return 0;
}